const AdminUserModel = require("../models/AdminUserModel")


const AdminUserSevire = {
    add: async (data) => {
        return await AdminUserModel.create({
            ...data
        })
    },
    put_info: async (verify, data) => {
        return await AdminUserModel.updateOne({
            username: verify.username,
            password: verify.password
        }, {
            ...data
        })
    },
    //登录
    login: async (data) => {
        //查询用户，返回所有字段除了password
        return await AdminUserModel.findOne({
            username: data.username,
            password: data.password
        }).select('-password')
    },
    //更新头像
    upload_img: async (verify, avatar) => {
        return await AdminUserModel.updateOne({
            username: verify.username,
            password: verify.password
        }, {
            avatar: avatar
        })
    },
    //更新密码
    renewal_pass: async (verify, password) => {
        return await AdminUserModel.updateOne({
            username: verify.username,
            password: verify.password
        }, {
            password: password
        })
    }
}

module.exports = AdminUserSevire